//
//  OperationAnalysisViewController.m
//  lsOA
//
//  Created by 蓝水软件 on 2016/10/21.
//  Copyright © 2016年 苏州蓝水有限公司. All rights reserved.
//

#import "OperationAnalysisViewController.h"
#import "OperationCollectionViewCell.h"
#import "HJCarouselViewLayout.h"
#import "YunyingViewController.h"
#import "BusinessViewController.h"


@interface OperationAnalysisViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
    UICollectionView *colView;

}
@property (nonatomic,strong)   NSArray *array;
@end

@implementation OperationAnalysisViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
    
    
}
- (NSArray *)array{
    
    _array = [NSArray new];
    _array = @[@[@"收入支出分析",@"",@""],@[@"集散中心",@"公交系统",@"旅游包车系统",@"出租车系统",@"安全系统",@"",@"",@"",@""]];
    return _array;
}



- (void)setUI{
    
    self.title = @"运营分析";
//    UIImage *backImage = [UIImage imageNamed:@"lanzi"];
//    backImage = [backImage applyDarkEffect];
    self.view.backgroundColor = [UIColor whiteColor];
    //初始化显示流
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(KSWidth/3-1, KSWidth/3);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 1;
    layout.headerReferenceSize = CGSizeMake(KSWidth, 30);
    layout.sectionInset = UIEdgeInsetsMake(0,0, 0, 1);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //初始化控件
    colView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    colView.backgroundColor = [UIColor colorWithHexString:@"#d7d7dd"];
    colView.showsHorizontalScrollIndicator = NO;
    colView.showsVerticalScrollIndicator = NO;
    //    colView.pagingEnabled = YES;
    [colView registerClass:[OperationCollectionViewCell class] forCellWithReuseIdentifier:@"myCell"];
    [colView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headView"];
    colView.delegate = self;
    colView.dataSource = self;
    [self.view addSubview:colView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

#pragma  collectionViewDeltgate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
  
    return [self.array[section] count];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return [self.array count];
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    NSArray *headTitleArray = @[@"综合分析",@"单项分析"];
    UICollectionReusableView* headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headView" forIndexPath:indexPath];
    UILabel *laebl = [[UILabel alloc]init];

    laebl.font = [UIFont boldSystemFontOfSize:16];
    laebl.textColor = [UIColor colorWithHexString:@"#71717a"];
    laebl.text = headTitleArray[indexPath.section];
    
    [headView addSubview:laebl];
    [laebl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(200);
        make.left.mas_equalTo(15);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(headView);
    }];
    headView.backgroundColor = [UIColor colorWithHexString:@"#f2f2f8"];
    return headView;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"myCell";
    OperationCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    cell.imageView.image  = [UIImage imageNamed:self.array[indexPath.section][indexPath.row]];
    cell.label.text = self.array[indexPath.section][indexPath.row];    
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [XHToast showTopWithText:@"测试数据,正式数据尽情期待!"];
    if (indexPath.section == 1 && indexPath.row == 1) {
        BusinessViewController *businessView = [BusinessViewController new];
        businessView.view.backgroundColor = [UIColor whiteColor];
        [self.navigationController pushViewController:businessView animated:YES];
    }else{
        YunyingViewController *ying = [YunyingViewController new];
        ying.view.backgroundColor = [UIColor whiteColor];
        [self.navigationController pushViewController:ying animated:YES];
    }


}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"指纹"]];
}

- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    cell.backgroundView = [UIView new];
    
}



@end
